﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UdrinkWater_Project.Officer
{
    public partial class BillManu : System.Web.UI.Page
    {
        public static string ManuDate;
        private string Connection = ConfigurationManager.ConnectionStrings["DB_Udrink"].ConnectionString;

        protected void Page_Load(object sender, EventArgs e)
        {
            ManuDate = Session["ManuDateID"].ToString();
            DataTable dtManuList = GetManuList(ManuDate);
            DataTable dtMatList = GetMatList(ManuDate);
            txtManuDate.Text = dtManuList.Rows[0]["Manu_Date"].ToString();
            txtEmpName.Text = dtManuList.Rows[0]["EmpName"].ToString();
            txtEmpID.Text = dtManuList.Rows[0]["Act_Officer"].ToString();
            Session["list"] = dtManuList.Rows.Count;
            gvMat.DataSource = dtMatList;
            gvMat.DataBind();
            gvManuList.DataSource = dtManuList;
            gvManuList.DataBind();

        }
        private DataTable GetManuList(string Date)
        {
            string sqltext = @"SELECT        TB_Manufacture.Manu_Date, TB_Manufacture.Product_ID,TB_Product.Product_name, TB_Unit_Category.Unit_Name, TB_Manufacture.Product_Count, TB_Manufacture.Act_Officer, 
                                             TB_Employee.Prefix + ' ' + TB_Employee.Firstname + ' ' + TB_Employee.Lastname AS EmpName
                               FROM          TB_Employee LEFT JOIN
                                             TB_Manufacture LEFT JOIN
                                             TB_Product LEFT JOIN
              TB_Unit_Category ON TB_Product.Unit = TB_Unit_Category.Unit_ID ON TB_Manufacture.Product_ID = TB_Product.Product_ID ON TB_Employee.ID_Card = TB_Manufacture.Act_Officer
                               WHERE TB_Manufacture.Manu_Date = '" + Date + "' ";
            SqlConnection sqlconn = new SqlConnection(Connection);
            SqlDataAdapter da = new SqlDataAdapter(sqltext, sqlconn);
            DataSet ds = new DataSet();
            da.Fill(ds);
            return ds.Tables[0];
        }
        private DataTable GetMatList(string Date)
        {
            string sqltext = @"SELECT        TB_ManufactureM_List.Manu_M_Date, TB_ManufactureM_List.Material_ID, TB_Material.Materail_name, TB_Unit_Category.Unit_Name, TB_ManufactureM_List.Material_Count
                               FROM          TB_ManufactureM_List LEFT OUTER JOIN
                                             TB_Material ON TB_ManufactureM_List.Material_ID = TB_Material.Material_ID LEFT OUTER JOIN
                                             TB_Unit_Category ON TB_Material.Unit = TB_Unit_Category.Unit_ID
                               WHERE TB_ManufactureM_List.Manu_M_Date = '" + Date + "' ";
            SqlConnection sqlconn = new SqlConnection(Connection);
            SqlDataAdapter da = new SqlDataAdapter(sqltext, sqlconn);
            DataSet ds = new DataSet();
            da.Fill(ds);
            return ds.Tables[0];
        }
        protected void ASPxButton1_Click(object sender, EventArgs e)
        {
            Response.Redirect("ReportManufac1.aspx");
        }

        protected void ASPxButton2_Click(object sender, EventArgs e)
        {
            Response.Redirect("ReportManufac2.aspx");
        }

    }
}